package cn.fy.navigation.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import android.os.Bundle;
import android.view.MenuItem;

import cn.fy.navigation.R;
import cn.fy.navigation.databinding.ActivityBottomNavigationViewBinding;

public class BottomNavigationViewActivity extends AppCompatActivity {

    private ActivityBottomNavigationViewBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_bottom_navigation_view);
        binding = ActivityBottomNavigationViewBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("BottomNavigationView");

        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navi_business, R.id.navi_msg, R.id.navi_mine)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.fragmentContainerViewMain);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(binding.bottomNavigationView, navController);

    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {

        switch (item.getItemId()) {
            case android.R.id.home:
                finish();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}